home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / GCC 1.37.1r14 / usr / gcc-1.37.1r14 / (gcc-1.37.π) / gencodes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-02  |  3.5 KB  |  161 lines  |  [TEXT/KAHL]

  1. /* Generate from machine description:
  2.  
  3.    - some macros CODE_FOR_... giving the insn_code_number value
  4.    for each of the defined standard insn names.
  5.    Copyright (C) 1987 Free Software Foundation, Inc.
  6.    Copyright (C) 1989, 1990 Apple Computer, Inc.
  7.  
  8. This file is part of GNU CC.
  9.  
  10. GNU CC is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 1, or (at your option)
  13. any later version.
  14.  
  15. GNU CC is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. GNU General Public License for more details.
  19.  
  20. You should have received a copy of the GNU General Public License
  21. along with GNU CC; see the file COPYING.  If not, write to
  22. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  23.  
  24.  
  25. #include <stdio.h>
  26. #include "config.h"
  27. #include "rtl.h"
  28. #include "obstack.h"
  29.  
  30. struct obstack obstack;
  31. struct obstack *rtl_obstack = &obstack;
  32.  
  33. #define obstack_chunk_alloc xmalloc
  34. #define obstack_chunk_free free
  35. extern int xmalloc ();
  36. extern void free ();
  37.  
  38. void fatal ();
  39. void fancy_abort ();
  40.  
  41. int insn_code_number;
  42.  
  43. void
  44. gen_insn (insn)
  45.      rtx insn;
  46. {
  47.   /* Don't mention instructions whose names are the null string.
  48.      They are in the machine description just to be recognized.  */
  49.   if (strlen (XSTR (insn, 0)) != 0)
  50.     printf ("  CODE_FOR_%s = %d,\n", XSTR (insn, 0),
  51.         insn_code_number);
  52. }
  53.  
  54. int
  55. xmalloc (size)
  56. {
  57.   register int val = (int)malloc (size);
  58.  
  59.   if (val == 0)
  60.     fatal ("virtual memory exhausted");
  61.   return val;
  62. }
  63.  
  64. int
  65. xrealloc (ptr, size)
  66.      char *ptr;
  67.      int size;
  68. {
  69.   int result = (int)realloc (ptr, size);
  70.   if (!result)
  71.     fatal ("virtual memory exhausted");
  72.   return result;
  73. }
  74.  
  75. void
  76. fatal (s, a1, a2)
  77.      char *s;
  78. {
  79.   fprintf (stderr, "gencodes: ");
  80.   fprintf (stderr, s, a1, a2);
  81.   fprintf (stderr, "\n");
  82.   exit (FATAL_EXIT_CODE);
  83. }
  84.  
  85. /* More 'friendly' abort that prints the line and file.
  86.    config.h can #define abort fancy_abort if you like that sort of thing.  */
  87.  
  88. void
  89. fancy_abort ()
  90. {
  91.   fatal ("Internal gcc abort.");
  92. }
  93.  
  94. int
  95. main (argc, argv)
  96.      int argc;
  97.      char **argv;
  98. {
  99.   rtx desc;
  100.   FILE *infile;
  101.   extern rtx read_rtx ();
  102.   register int c;
  103.  
  104.   obstack_init (rtl_obstack);
  105.  
  106.   if (argc <= 1)
  107.     fatal ("No input file name.");
  108.  
  109.   infile = fopen (argv[1], "r");
  110.   if (infile == 0)
  111.     {
  112.       perror (argv[1]);
  113.       exit (FATAL_EXIT_CODE);
  114.     }
  115.  
  116.   init_rtl ();
  117.  
  118.   printf ("/* Generated automatically by the program `gencodes'\n\
  119. from the machine description file `md'.  */\n\n");
  120.  
  121.   printf ("#ifndef MAX_INSN_CODE\n\n");
  122.  
  123.   /* Read the machine description.  */
  124.  
  125.   insn_code_number = 0;
  126.   printf ("enum insn_code {\n");
  127.  
  128.   while (1)
  129.     {
  130.       c = read_skip_spaces (infile);
  131.       if (c == EOF)
  132.     break;
  133.       ungetc (c, infile);
  134.  
  135.       desc = read_rtx (infile);
  136.       if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
  137.     {
  138.       gen_insn (desc);
  139.       insn_code_number++;
  140.     }
  141.       if (GET_CODE (desc) == DEFINE_PEEPHOLE)
  142.     {
  143.       insn_code_number++;
  144.     }
  145.     }
  146.  
  147. #ifdef APPLE_HAX
  148.   /* The gen'ed code ought to be mpw_c ifdefed, but that's complicated */
  149.   printf ("  CODE_FOR_nothing, insn_code_intifier = 1000000 };\n");
  150. #else
  151.   printf ("  CODE_FOR_nothing };\n");
  152. #endif /* APPLE_HAX */
  153.  
  154.   printf ("\n#define MAX_INSN_CODE ((int) CODE_FOR_nothing)\n");
  155.  
  156.   printf ("#endif /* MAX_INSN_CODE */\n");
  157.  
  158.   fflush (stdout);
  159.   exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
  160. }
  161.